<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box1">
        <h2></h2>
        <ul></ul>
    </div>
    <div class="box2">
        <h2></h2>
        <img src="" alt="" style="width: 100px;" />
        <ul></ul>
    </div>
    <script>
        var data1 = {
            title: "体育",
            list: ["体育-1", "体育-2", "体育-3"]
        }
        var data2 = {
            title: "综艺",
            url: "https://fanyi-cdn.cdn.bcebos.com/static/translation/img/header/logo_e835568.png",
            list: ["综艺 - 1", "综艺 - 2", "综艺3"]
        }
        class CreateBox {
            constructor(select, data) {
                this.ele = document.querySelector(select)
                this.title = data.title
                this.list = data.list
                this.render()
            }
            render() {
                let oh1 = this.ele.querySelector("h2")
                let oul = this.ele.querySelector("ul")
                oh1.innerHTML = this.title
                oul.innerHTML = this.list.map(item =>
                    `<li>${item}</li>`).join("")
            }
        }

        new CreateBox(".box1", data1)

        //因为只多了个图片，所以直接继承CreatBox即可
        class CreateImgBox extends CreateBox {
            constructor(select, data) {
                super(select, data)
                this.imgUrl = data.url
                this.render() //这里需要重新调用一下render()，与this指向有关
            }
            render() {
                super.render()
                let oimg = this.ele.querySelector("img")
                oimg.src = this.imgUrl
            }
        }

        new CreateImgBox(".box2", data2)
    </script>
</body>

</html>